#!/usr/bin/env python3
# _*_coding:utf-8 _*_
__author__ = "Gao"
'''检验图片文件的完整性'''

import io
from PIL import Image


def is_valid_image(pathfile):
    '''传入文件路径，判断是否是图片'''
    valid = True
    try:
        Image.open(pathfile).verify()
    except:
        valid = False
    return valid


def is_valid_image_bytes(buf):
    '''传入二进制流，判断是否是图片'''
    valid = True
    try:
        Image.open(io.BytesIO(buf)).verify()
    except:
        valid = False
    return valid
